package zoo;

import java.util.ArrayList;
import java.util.List;

public class Zone implements AnimalAccess,ShowAnimal{
    protected List<Animal> AnimalList;
    public Zone() {
        this.AnimalList = new ArrayList<Animal>();
    }
    @Override
    public boolean addAnimal(Animal animal) {
        return this.AnimalList.add(animal);

    }

    @Override
    public boolean deleteAnimal(Animal animal) {
        return this.AnimalList.remove(animal);
    }

    @Override
    public Animal findAnimal(String name) {
        Animal foundAnimal = null;
        //用foreach循环遍历
        for( Animal animal : this.AnimalList ){
            if (animal.getAnimalname().equals(name)) {
                foundAnimal = animal;
            }
        }
        if(foundAnimal==null){
            System.out.println("未找到目标动物");
        }
        return foundAnimal;
    }

    @Override
    public void ShowAllAnimal() {
        System.out.println("该区域有:");
        for( Animal animal : this.AnimalList ){
            System.out.println("姓名:"+animal.getAnimalname()+
                    " 调温方式:"+animal.getTemperature()+
                    " 繁殖方式:"+animal.getReproductive_methods());
        }
    }
    @Override
    public  void ShowAnimalNumber(){
        System.out.println("该区域现有动物总数"+AnimalList.size());
    }
}


